package cn.Controller;

import cn.Service.AdminService;
import cn.entity.*;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.UUID;

@Controller
@Transactional
public class AdminController {
    @Autowired
    private AdminService adminService;


    //修改admin账户密码
    @RequestMapping("/updatePassword.do")

    public String updateAdmin(Admin admin, HttpServletResponse response) throws IOException {

        System.out.println(admin.toString());
        int i = adminService.updateAdmin(admin);


        return "login";


    }

    //admin退出
    @RequestMapping("/adminToLogout.do")
    public String exitAdmin(HttpServletRequest request) {

        request.removeAttribute("ADMIN");

        return "login";

    }
    //会员管理

    @RequestMapping("/selectAllUser.do")
    public String selectUserAll(@RequestParam(name = "startPage", defaultValue = "1") Integer startPage, Model model) {
        PageHelper.startPage(startPage, 5);

        List<User> users = adminService.userAlllist();

        model.addAttribute("USERS", users);
        PageInfo<User> pageInfo = new PageInfo(users);
        System.out.println("***********" + pageInfo.toString());
        model.addAttribute("PAGE", pageInfo);
        model.addAttribute("select","select");


        return "show_users";
    }


    //会员管理条件查询
    @RequestMapping("/selectUserBywz.do")
    public String selectUserBywz(@RequestParam(name = "startPage", defaultValue = "1") Integer startPage,@RequestParam(name = "select") String select, @RequestParam(name = "exampleInputEmail3") String exampleInputEmail3, Model model) {

        User user=new User();
        System.out.println(select + "***" + exampleInputEmail3);
        if ("uid".equals(select)) {
            if (exampleInputEmail3 != null && exampleInputEmail3 != "") {
                int i = Integer.parseInt(exampleInputEmail3);
                user.setUid(i);
                PageHelper.startPage(startPage, 5);
                List<User> users = adminService.selectUserBywz(user);
                model.addAttribute("USERS", users);
                PageInfo pageInfo = new PageInfo(users);
                model.addAttribute("PAGE", pageInfo);
                System.out.println(users);
                model.addAttribute("exampleInputEmail3", exampleInputEmail3);
                model.addAttribute("select", select);
                return "show_users";
            } else {
                PageHelper.startPage(startPage, 5);
                List<User> users10 = adminService.userAlllist();
                model.addAttribute("USERS", users10);
                PageInfo pageInfo10 = new PageInfo(users10);
                model.addAttribute("PAGE", pageInfo10);
                model.addAttribute("exampleInputEmail3", exampleInputEmail3);
                model.addAttribute("select", select);

                return "show_users";

            }
        } else if ("username".equals(select)) {
            user.setUsername(exampleInputEmail3);
            PageHelper.startPage(startPage, 5);
            List<User> users1 = adminService.selectUserBywz(user);
            PageInfo pageInfo1 = new PageInfo(users1);
            model.addAttribute("USERS", users1);
            model.addAttribute("PAGE", pageInfo1);
            model.addAttribute("exampleInputEmail3", exampleInputEmail3);
            model.addAttribute("select", select);
            return "show_users";
        } else if ("sex".equals(select)) {
            user.setSex(exampleInputEmail3);
            PageHelper.startPage(startPage, 2);
            List<User> users2 = adminService.selectUserBywz(user);

            System.out.println(users2.toString());
            model.addAttribute("USERS", users2);
            PageInfo pageInfo2 = new PageInfo(users2);
            model.addAttribute("PAGE", pageInfo2);
            model.addAttribute("exampleInputEmail3", exampleInputEmail3);
            model.addAttribute("select", select);
            return "show_users";
        } else if ("name".equals(select)) {
            user.setName(exampleInputEmail3);
            PageHelper.startPage(startPage, 5);
            List<User> users3 = adminService.selectUserBywz(user);
            model.addAttribute("USERS", users3);
            PageInfo pageInfo3 = new PageInfo(users3);
            model.addAttribute("PAGE", pageInfo3);
            model.addAttribute("exampleInputEmail3", exampleInputEmail3);
            model.addAttribute("select", select);
            return "show_users";
        } else if ("all".equals(select)) {
            PageHelper.startPage(startPage, 5);
            List<User> users10 = adminService.userAlllist();
            model.addAttribute("USERS", users10);
            PageInfo pageInfo10 = new PageInfo(users10);
            model.addAttribute("PAGE", pageInfo10);
            model.addAttribute("exampleInputEmail3", exampleInputEmail3);
            model.addAttribute("select", select);
            return "show_users";
        }
        return "show_users";


    }
    //评论管理
    @RequestMapping("/selectAllComments.do")
    public String selectComment(@RequestParam(name = "startPage", defaultValue = "1") Integer startPage,Model model){
        PageHelper.startPage(startPage,5);
        List<Product> product = adminService.getProduct();
        PageInfo pageInfo=new PageInfo(product);
        System.out.println("商品数量"+product.size());
        model.addAttribute("products",product);
        model.addAttribute("PAGE",pageInfo);
        model.addAttribute("select","select");



        /*List<Comment> comments = adminService.selectCommentAll();
        System.out.println(comments.toString());
        PageInfo<Comment> pageInfo=new PageInfo<>(comments);
        System.out.println(pageInfo.toString());
        model.addAttribute("COMMENTS",comments);
        model.addAttribute("PAGE",pageInfo);*/


        return "comment_show_products";
    }
    //评论管理查询
    @RequestMapping("/selectpinglunproduct.do")
    public String selectpinglunproduct(@RequestParam("select") String select,@RequestParam("exampleInputEmail2") String exampleInputEmail2,@RequestParam(name = "startPage",defaultValue = "1")Integer startPage, Model model){
        System.out.println(select);
        System.out.println(exampleInputEmail2);
        if ("all".equals(select)) {
            PageHelper.startPage(startPage, 5);
            List<Product> products10 = adminService.getProduct();
            model.addAttribute("products", products10);
            PageInfo pageInfo10 = new PageInfo(products10);
            model.addAttribute("PAGE", pageInfo10);
            model.addAttribute("select", select);
            model.addAttribute("exampleInputEmail2", exampleInputEmail2);

            return "comment_show_products";
        } else if ("pid".equals(select)) {
            if (exampleInputEmail2 == null || exampleInputEmail2.equals("")) {
                PageHelper.startPage(startPage, 5);
                List<Product> products = adminService.getProduct();
                model.addAttribute("products", products);
                PageInfo pageInfo = new PageInfo(products);
                model.addAttribute("PAGE", pageInfo);
                model.addAttribute("select", select);
                model.addAttribute("exampleInputEmail2", exampleInputEmail2);

                return "comment_show_products";
            }
            int i = Integer.parseInt(exampleInputEmail2);
            PageHelper.startPage(startPage, 5);
            List<Product> products = adminService.getselectProduct(i);
            System.out.println("根据pid查询");
            PageInfo pageInfo = new PageInfo(products);
            model.addAttribute("products", products);
            model.addAttribute("PAGE", pageInfo);
            model.addAttribute("select", select);
            model.addAttribute("exampleInputEmail2", exampleInputEmail2);
            return "comment_show_products";
        } else if ("pname".equals(select)) {
            PageHelper.startPage(startPage, 5);
            List<Product> products1 = adminService.getselectProductByname(exampleInputEmail2);
            System.out.println("根据pname查询");
            PageInfo pageInfo1 = new PageInfo(products1);
            model.addAttribute("products", products1);
            model.addAttribute("PAGE", pageInfo1);
            model.addAttribute("select", select);
            model.addAttribute("exampleInputEmail2", exampleInputEmail2);
            return "comment_show_products";
        } else if ("pmaterial".equals(select)) {
            PageHelper.startPage(startPage, 5);
            List<Product> products2 = adminService.getselectProductBypmaterial(exampleInputEmail2);
            System.out.println("根据材料查询");
            PageInfo pageInfo2 = new PageInfo(products2);
            model.addAttribute("products", products2);
            model.addAttribute("PAGE", pageInfo2);
            model.addAttribute("select", select);
            model.addAttribute("exampleInputEmail2", exampleInputEmail2);
            return "comment_show_products";
        }
        return "comment_show_products";
    }

    //查看评论
    @RequestMapping("/showpinglun.do")
    public String selectPinglun(@RequestParam("pid")Integer pid,@RequestParam(name = "startPage", defaultValue = "1") Integer startPage,Model model){
        PageHelper.startPage(startPage,2);
        List<ShowPingLun> showPingLuns = adminService.selectShowPingLunBypid(pid);
        model.addAttribute("showPingLuns",showPingLuns);
        PageInfo pageInfo =new PageInfo(showPingLuns);
        model.addAttribute("PAGE",pageInfo);
        model.addAttribute("pid",pid);
        return "message_manage";
    }




    //订单查询
    @RequestMapping("/selectAllOrder.do")
    public String selectOrderAll(@RequestParam(name = "startPage", defaultValue = "1") Integer startPage,Model model){
        PageHelper.startPage(startPage,5);
        List<Order> orders = adminService.selectOrderAll();
        PageInfo<Order> pageInfo=new PageInfo(orders);
        model.addAttribute("ORDERS",orders);
        model.addAttribute("PAGE",pageInfo);
        model.addAttribute("select","select");

        return "order_manage";
    }

    //订单条件查
    @RequestMapping("/selectOrderBywz.do")
    public String selectProductByWZ(@RequestParam(name = "startPage", defaultValue = "1") Integer startPage,@RequestParam("select") String select, @RequestParam("value") String value,Model model){
        System.out.println(select + "**" +value );

        Order order=new Order();

        if ("all".equals(select)) {
            PageHelper.startPage(startPage, 5);
            List<Order> orders4 = adminService.selectOrderAll();

            model.addAttribute("ORDERS", orders4);
            PageInfo pageInfo4 = new PageInfo(orders4);
            model.addAttribute("PAGE", pageInfo4);
            model.addAttribute("select", select);
            model.addAttribute("value", value);
            return "order_manage";
        } else if ("onum".equals(select)) {
            order.setOnum(value);
            PageHelper.startPage(startPage, 5);
            List<Order> orders = adminService.selectOrderBywz(order);
            model.addAttribute("ORDERS", orders);
            PageInfo pageInfo = new PageInfo(orders);
            model.addAttribute("PAGE", pageInfo);
            model.addAttribute("select", select);
            model.addAttribute("value", value);

            return "order_manage";
        } else if ("address".equals(select)) {
            order.setAddress(value);
            PageHelper.startPage(startPage, 5);
            List<Order> orders1 = adminService.selectOrderBywz(order);
            model.addAttribute("ORDERS", orders1);
            PageInfo pageInfo1 = new PageInfo(orders1);
            model.addAttribute("PAGE", pageInfo1);
            model.addAttribute("select", select);
            model.addAttribute("value", value);

            return "order_manage";
        } else if ("ostate".equals(select)) {
            String ostate = value.equals("未付款") ? "0" : value.equals("已付款待发货") ? "1" : value.equals("部分发货待收货") ? "2" : value.equals("全部发货待收货") ? "3" : value.equals("已收货") ? "4" : value.equals("") ? "5" : "6";
            System.out.println(ostate);
            if (ostate != "6") {
                System.out.println(ostate + "**111");

                if (ostate.equals("5")) {
                    System.out.println(ostate + "**222");

                    PageHelper.startPage(startPage, 5);
                    List<Order> orders5 = adminService.selectOrderAll();

                    model.addAttribute("ORDERS", orders5);
                    PageInfo pageInfo5 = new PageInfo(orders5);
                    model.addAttribute("PAGE", pageInfo5);
                    model.addAttribute("select", select);
                    model.addAttribute("value", value);
                    return "order_manage";
                } else {
                    System.out.println(ostate + "**333");

                    order.setOstate(ostate);
                    PageHelper.startPage(startPage, 5);

                    List<Order> orders2 = adminService.selectOrderBywz(order);
                    model.addAttribute("ORDERS", orders2);
                    PageInfo pageInfo2 = new PageInfo(orders2);
                    model.addAttribute("PAGE", pageInfo2);
                    model.addAttribute("select", select);
                    model.addAttribute("value", value);

                    return "order_manage";

                }

            } else {
                return "order_manage";
            }
        } else if ("receiver".equals(select)) {
            order.setReceiver(value);

            PageHelper.startPage(startPage, 5);

            List<Order> orders3 = adminService.selectOrderBywz(order);
            model.addAttribute("ORDERS", orders3);
            PageInfo pageInfo3 = new PageInfo(orders3);
            model.addAttribute("PAGE", pageInfo3);
            model.addAttribute("select", select);
            model.addAttribute("value", value);

            return "order_manage";
        }
        return "order_manage";


    }


    //发货
    @RequestMapping("/showEditOrder.do")
    @ResponseBody
    public void updateOrderostate(@RequestParam("onum")String onum,@RequestParam("pid")int pid,HttpServletResponse response) throws IOException {
        System.out.println(onum + "***" + pid);
        System.out.println("****");
        Order order = adminService.selectOrderByonum(onum);

        List<OrderItem> order_items = adminService.selectListOrder_itemByorder_id(order.getOid());

        for (OrderItem order_item : order_items) {

            adminService.updateOrder_itemSend_countByid(order_item.getPay_count(),order_item.getId());

            Product productById = adminService.getProductById(order_item.getPid());


        }
        adminService.updateOrderByoid("2",order.getOid());





    }


    //查看出货单
    @RequestMapping("/showOrderDetails.do")
    public String showOrderDetails(@RequestParam("orderId")int orderId, Model model){
        System.out.println(orderId);
        List<OrderDetails> orderDetails = adminService.selectOrderDetails(orderId);
        System.out.println(orderDetails);
        model.addAttribute("data",orderDetails);
        return "order_details";
    }



    @RequestMapping("/selectAllProduct.do")
    public String getproduct(@RequestParam(name = "startPage",defaultValue = "1")Integer startPage, Model model){
        PageHelper.startPage(startPage,8);
        List<Product> product = adminService.getProduct();
        PageInfo pageInfo=new PageInfo(product);
        System.out.println("商品数量"+product.size());
        model.addAttribute("products",product);
        model.addAttribute("PAGE",pageInfo);
        model.addAttribute("select","select");
        return "show_products";
    }

    @RequestMapping("/select.do")
    public String getselect(@RequestParam ("select") String select,@RequestParam(name = "exampleInputEmail2",required = false) String exampleInputEmail2,@RequestParam(name = "startPage",defaultValue = "1")Integer startPage, Model model){
        System.out.println(select);
        System.out.println(exampleInputEmail2);
        if ("all".equals(select)) {
            PageHelper.startPage(startPage, 8);
            List<Product> products10 = adminService.getProduct();
            model.addAttribute("products", products10);
            PageInfo pageInfo10 = new PageInfo(products10);
            model.addAttribute("PAGE", pageInfo10);
            model.addAttribute("select", select);
            model.addAttribute("exampleInputEmail2", exampleInputEmail2);

            return "show_products";
        } else if ("pid".equals(select)) {
            if (exampleInputEmail2 == null || exampleInputEmail2.equals("")) {
                PageHelper.startPage(startPage, 8);
                List<Product> products = adminService.getProduct();
                model.addAttribute("products", products);
                PageInfo pageInfo = new PageInfo(products);
                model.addAttribute("PAGE", pageInfo);
                model.addAttribute("select", select);
                model.addAttribute("exampleInputEmail2", exampleInputEmail2);

                return "show_products";
            }
            int i = Integer.parseInt(exampleInputEmail2);
            PageHelper.startPage(startPage, 8);
            List<Product> products = adminService.getselectProduct(i);
            System.out.println("根据pid查询");
            PageInfo pageInfo = new PageInfo(products);
            model.addAttribute("products", products);
            model.addAttribute("PAGE", pageInfo);
            model.addAttribute("select", select);
            model.addAttribute("exampleInputEmail2", exampleInputEmail2);
            return "show_products";
        } else if ("pname".equals(select)) {
            PageHelper.startPage(startPage, 8);
            List<Product> products1 = adminService.getselectProductByname(exampleInputEmail2);
            System.out.println("根据pname查询");
            PageInfo pageInfo1 = new PageInfo(products1);
            model.addAttribute("products", products1);
            model.addAttribute("PAGE", pageInfo1);
            model.addAttribute("select", select);
            model.addAttribute("exampleInputEmail2", exampleInputEmail2);
            return "show_products";
        } else if ("pmaterial".equals(select)) {
            PageHelper.startPage(startPage, 8);
            List<Product> products2 = adminService.getselectProductBypmaterial(exampleInputEmail2);
            System.out.println("根据材料查询");
            PageInfo pageInfo2 = new PageInfo(products2);
            model.addAttribute("products", products2);
            model.addAttribute("PAGE", pageInfo2);
            model.addAttribute("select", select);
            model.addAttribute("exampleInputEmail2", exampleInputEmail2);
            return "show_products";
        }else if ("num".equals(select)){
            if (exampleInputEmail2==null||exampleInputEmail2.equals("")){
                PageHelper.startPage(startPage,8);
                List<Product> products11 = adminService.getProduct();
                model.addAttribute("products",products11);
                PageInfo pageInfo11=new PageInfo(products11);
                model.addAttribute("PAGE",pageInfo11);
                model.addAttribute("select",select);
                model.addAttribute("exampleInputEmail2",exampleInputEmail2);
                return "show_products";
            }
            int j = Integer.parseInt(exampleInputEmail2);
            PageHelper.startPage(startPage,8);
            List<Product> products12 = adminService.selectProductByNum(j);
            System.out.println("根据pid查询");
            PageInfo pageInfo12=new PageInfo(products12);
            model.addAttribute("products",products12);
            model.addAttribute("PAGE",pageInfo12);
            model.addAttribute("select",select);
            model.addAttribute("exampleInputEmail2",exampleInputEmail2);
            return "show_products";
        }else if ("cname".equals(select)){
            if (exampleInputEmail2==null||exampleInputEmail2.equals("")){
                PageHelper.startPage(startPage,8);
                List<Product> products11 = adminService.getProduct();
                model.addAttribute("products",products11);
                PageInfo pageInfo11=new PageInfo(products11);
                model.addAttribute("PAGE",pageInfo11);
                model.addAttribute("select",select);
                model.addAttribute("exampleInputEmail2",exampleInputEmail2);
                return "show_products";
            }

            PageHelper.startPage(startPage,8);
            List<Product> products = adminService.selectProductByCid(exampleInputEmail2);
            System.out.println("根据pid查询");
            PageInfo pageInfo12=new PageInfo(products);
            model.addAttribute("products",products);
            model.addAttribute("PAGE",pageInfo12);
            model.addAttribute("select",select);
            model.addAttribute("exampleInputEmail2",exampleInputEmail2);
            return "show_products";

        }
        return "show_products";
    }

    @RequestMapping("/updateProduct.do")
    public void updateproduct(Product product, HttpServletResponse response){
        Integer pid = product.getPid();
        System.out.println("修改商品的id"+pid);
        System.out.println(product);
        int i = adminService.updateProduct(product);
        if (i>0){
            try {
                response.getWriter().write("OK");
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    @RequestMapping("/deleteProduct.do")
    @ResponseBody
    public  void deleteproduct(Product product, HttpServletResponse response) throws IOException {
        Integer pid = product.getPid();
        System.out.println("删除商品的id"+pid);
        List<OrderItem> order_itemByPid = adminService.getOrder_itemByPid(pid);
        System.out.println("***********"+order_itemByPid.size());
        if (order_itemByPid.size()>0) {
            for (OrderItem order_item : order_itemByPid) {
                System.out.println("订单详情的id" + order_item.getOrder_id());
                List<Order> orderByoid = adminService.getOrderByoid(order_item.getOrder_id());
                for (Order order : orderByoid) {
                    String ostate = order.getOstate();
                    System.out.println(ostate.equals("4"));
                    if (!ostate.equals("4")) {
                        response.getWriter().write("NO");
                        System.out.println("888888888888");
                    }else{
                        System.out.println("999999");
                        int i1 = adminService.deleteComment(pid);
                        int i = adminService.deleteProduct(pid);
                        System.out.println(i);
                        response.getWriter().write("OK");
                    }
                }
            }
        }
        if (order_itemByPid.size()==0){
            int i1 = adminService.deleteComment(pid);
            int i = adminService.deleteProduct(pid);
            if (i > 0) {
                try {
                    response.getWriter().write("OK");
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    @RequestMapping("/addProduct.do")
    public String addproduct(Product product){
        String pimage = product.getPimage();
        System.out.println("***********"+pimage);
        product.setPimage("product/"+pimage);
        System.out.println("添加");
        int i = adminService.addProduct(product);
        if (i>0){
            return "redirect:/selectAllProduct.do";
        }else {
            return "add_product";
        }
    }

    @RequestMapping("/productBillList.do")
    public String getpruductbill(@RequestParam(name = "startPage",defaultValue = "1")Integer startPage,Model model){
        PageHelper.startPage(startPage,5);
        List<Product_bill> product_bill = adminService.getProduct_bill();
        PageInfo pageInfo=new PageInfo(product_bill);
        System.out.println("进货查询");
        System.out.println(product_bill.size());
        model.addAttribute("product_bill",product_bill);
        model.addAttribute("PAGE",pageInfo);
        return "product_bill";

    }


    @RequestMapping("/editProductBill.do")
    @ResponseBody
    public void updateproductbill(Product_bill product_bill){
        Date date = new Date();
        SimpleDateFormat dateFormatateFormat = new SimpleDateFormat("yyyy-MM-dd : hh:mm:ss");
        String format = dateFormatateFormat.format(date);
        System.out.println("****当前时间"+format);
        product_bill.setUpdate_time(format);
        int i = adminService.updateProduct_bill(product_bill);
    }

    @RequestMapping("/addProductBill.do")
    @ResponseBody
    public void addproductbill(Product_bill product_bill,HttpServletResponse response){
        UUID uuid = UUID.randomUUID();
        String s = uuid.toString();
        String substring = s.substring(0, 6);
        System.out.println("随机生成的进货编号"+substring);
        product_bill.setId(substring);
        Date date = new Date();
        SimpleDateFormat dateFormatateFormat = new SimpleDateFormat("yyyy-MM-dd : hh:mm:ss");
        String format = dateFormatateFormat.format(date);
        product_bill.setCreate_time(format);
        product_bill.setUpdate_time(format);

        int i = adminService.addProduct_bill(product_bill);
        if (i>0){
            try {
                System.out.println("*******");
                response.getWriter().write("OK");
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    @RequestMapping("/deleteProductBill.do")
    @ResponseBody
    public void deleteproductbill(@Param("id") String id){
        //String id = product_bill.getId();
        System.out.println("删除进货编号"+id);
        int i = adminService.deleteProduct_bill(id);
    }

    @RequestMapping("/updataproductByPid.do")
    public String getproductbyid(@Param("pid") Integer pid,Model model){
        Product product = adminService.getProductById(pid);
        List<Category> categories = adminService.selecttb_categoryAll();
        System.out.println(product);
        model.addAttribute("categories",categories);
        model.addAttribute("product",product);
        return "productupdata";


    }



    //添加分类
    @RequestMapping("/inserttb_category.do")
    @ResponseBody
    public void inserttb_category(@RequestParam("cname")String cname,HttpServletResponse response) throws IOException {

        Category category = adminService.selectCategoryCnameByCname(cname);
        if (category == null) {
            adminService.insertCategory(cname);
            response.getWriter().write("OK");
        }else {
            response.getWriter().write("NO");
        }
    }
    //删除分类查看分类
    @RequestMapping("/selecttb_category.do")
    public String selecttb_category(Model model){
        List<Category> category = adminService.selecttb_categoryAll();
        System.out.println(category.toString());
        model.addAttribute("category",category);

        return "delectCategrory";
    }

    //删除分类
    @RequestMapping("/deletetb_category.do")
    @ResponseBody
    public void deletetb_category(@RequestParam("select")Integer select, HttpServletResponse response) throws IOException {
        System.out.println(select);

        List<Product> productListByCid = adminService.getProductListByCid(select);
        System.out.println(productListByCid.toString());
        if (productListByCid.size()==0) {
            System.out.println("888888888");
            adminService.deleteCategoryBycid(select);
            response.getWriter().write("OK");
        }else
        {
            System.out.println("99999");
            response.getWriter().write("ON");
        }


    }

    //添加商品查看分类
    @RequestMapping("/addPrdouctShowCategory.do")
    public String addPrdouctShowCategory(Model model){
        List<Category> category = adminService.selecttb_categoryAll();

        model.addAttribute("category",category);

        return "add_product";
    }



    @RequestMapping("/updateUserStop.do")
    public String updateUserStop(@RequestParam("uid")Integer uid,@RequestParam("stop")int stop, Model model){
        System.out.println(uid+"**"+stop);
        if (stop == 0) {
            adminService.updateUserStop(1,uid);
        }else {
            adminService.updateUserStop(0,uid);
        }


        return "redirect:selectAllUser.do";
    }





}











